//
//  NetworkCheck.m
//  HeroCar
//
//  Created by rui on 1/10/15.
//  Copyright (c) 2015 SZZCIT. All rights reserved.
//

#import "NetworkCheck.h"
#import "Reachability.h"
#import "BaseViewController.h"

@implementation NetworkCheck

+(void)checkNetwork:(id)VC
{
	dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
		Reachability *r = [Reachability reachabilityWithHostName:@"www.baidu.com"];
		
		NSString *str=[[NSString alloc] init];
		
		switch ([r currentReachabilityStatus]) {
			case NotReachable:
				str= @"没有网络连接";
				break;
			case ReachableViaWWAN:
				str= @"使用3G网络";
				break;
			case ReachableViaWiFi:
				str= @"使用WiFi网络";
				break;
		}
        
        NSString *alertStr=[NSString stringWithFormat:@"当前%@,访问服务器超时-.-!",str];
        
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"                                                    message:alertStr
//                                                       delegate:nil
//                                              cancelButtonTitle:@"确定" otherButtonTitles:nil];
        dispatch_async(dispatch_get_main_queue(), ^{ // 2
//            [alert show]; // 3
//            [(BaseViewController *)VC alertError:alertStr view:((BaseViewController *)VC).view animated:NO afterDelay:2.0];
            [gAlert show:alertStr delegate:nil withCloseButton:YES];
        });
		
//		if ([str isEqualToString:@"没有网络连接"]) {
//			UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"                                                    message:@"无法连接到Internet"
//														   delegate:nil
//												  cancelButtonTitle:@"确定" otherButtonTitles:nil];
//			dispatch_async(dispatch_get_main_queue(), ^{ // 2
//				[alert show]; // 3
//			});
//		}
//        else
//        {
//            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"                                                    message:@"服务器返回失败"
//                                                           delegate:nil
//                                                  cancelButtonTitle:@"确定" otherButtonTitles:nil];
//            dispatch_async(dispatch_get_main_queue(), ^{ // 2
//                [alert show]; // 3
//            });
//        }
	});
}


@end
